//package com.ksd.web.controller.system;
//
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.JsonNode;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.ksd.common.config.PlayControlConfig;
//import com.ksd.common.core.controller.BaseController;
//import com.ksd.common.core.domain.AjaxResult;
//import com.ksd.common.utils.StringUtils;
//import com.ksd.quartz.util.TaskConstans;
//import com.ksd.system.domain.*;
//import com.ksd.system.service.*;
//import com.ksd.web.controller.domain.SysChannelListBean;
//import com.ksd.web.controller.domain.SysFreqsListBean;
//import com.ksd.web.controller.m3beans.*;
//import com.ksd.web.controller.service.SendChannelService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.ArrayList;
//import java.util.HashSet;
//import java.util.List;
//import java.util.Set;
//
///**
// * 频道搜索Controller
// *
// * @author y.wu
// * @date 2025-01-08
// */
//@RestController
//@RequestMapping("/system/outputSet")
//public class SysOutputSetController2 extends BaseController
//{
//    @Autowired
//    private ISysOperLogService sysOperLogService;
//    @Autowired
//    private ISysChannelOneService sysChannelOneService;
//    @Autowired
//    private ISysChannelTwiceService sysChannelTwiceService;
//    @Autowired
//    private SendChannelService sendChannelService;
//    @Autowired
//    private ISysFreqOneService sysFreqOneService;
//    @Autowired
//    private ISysFreqTwiceService sysFreqTwiceService;
//    @Autowired
//    private ISysBoardService sysBoardService;
//    @Autowired
//    private ISysChannelTemplateService sysChannelTemplateService;
//
//    /**
//     * 查询网络配置列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:outputSet:list')")
//    @GetMapping("/list")
//    public AjaxResult list(QueryInfo queryInfo) {
//        //前端页面每一次点击输出设置页面时,都要根据直播网卡,重新获取一遍最新搜索出来的数据
//        String board = queryInfo.getBoard();
//        if (StringUtils.isNotEmpty(board)){
//            if (TaskConstans.boardValue1.equals(board)){
//                SysFreqOne sysFreqOne = new SysFreqOne();
//                sysFreqOne.setBoardId(Long.valueOf(queryInfo.getBoard()));
//                List<SysFreqOne> sysFreqOnes = sysFreqOneService.selectSysFreqList(sysFreqOne);
//                System.out.println("sysFreqs size sysFreqOnes:" + sysFreqOnes.size());
//                if (sysFreqOnes.size() != 0){
//                    return AjaxResult.success(sysFreqOnes);
//                }else{
//                    List<SysFreqOne> list = new ArrayList<>();
//                    SysFreqOne freqOne = new SysFreqOne();
//                    sysFreqOne.setNumber(1L);
//                    sysFreqOne.setFreq(12020L);
//                    list.add(freqOne);
//                    return AjaxResult.success(list);
//                }
//
//            }else{
//                SysFreqTwice sysFreqTwice = new SysFreqTwice();
//                sysFreqTwice.setBoardId(Long.valueOf(queryInfo.getBoard()));
//                List<SysFreqTwice> sysFreqTwices = sysFreqTwiceService.selectSysFreqList(sysFreqTwice);
//                System.out.println("sysFreqs size sysFreqTwice:" + sysFreqTwices.size());
//                if (sysFreqTwices.size() != 0){
//                    return AjaxResult.success(sysFreqTwices);
//                }else {
//                    List<SysFreqTwice> list = new ArrayList<>();
//                    SysFreqTwice freqTwice = new SysFreqTwice();
//                    sysFreqTwice.setNumber(1L);
//                    sysFreqTwice.setFreq(12020L);
//                    list.add(freqTwice);
//                    return AjaxResult.success(list);
//                }
//
//            }
//
//        }
//
//        return error();
//    }
//
//    @PostMapping("/getServiceInfoDataList")
//    public AjaxResult getServiceInfoDataList(@RequestBody QueryInfo queryInfo)
//    {
//        //每次
//        SysChannelListBean sysChannelListBean = new SysChannelListBean();
//        String board = queryInfo.getBoard();
//        if (TaskConstans.boardValue1.equals(board)){
//            SysChannelOne sysChannel = new SysChannelOne();
//            sysChannel.setBoardId(Long.valueOf(board));
//            sysChannel.setFreq(Long.valueOf(queryInfo.getFreq()));
//            List<SysChannelOne> sysChannels = sysChannelOneService.selectSysChannelList(sysChannel);
//            String tempIp = PlayControlConfig.getChannelIpStart();
//            Integer j = 0;
//            List<SysChannel> sysChannelList1 = new ArrayList<>();
//            for (SysChannelOne channel : sysChannels) {
//                j++;
//                String ip = channel.getIp();
//                String port = channel.getPort();
//                if (StringUtils.isEmpty(ip)){
//                    channel.setIp(tempIp+j);
//                }
//                if (StringUtils.isEmpty(port)){
//                    channel.setPort(PlayControlConfig.getChannelPort());
//                }
//                sysChannelOneService.updateSysChannel(channel);
//
//                SysChannel sysChannelTemp = channel.setOneObjec(channel);
//                sysChannelList1.add(sysChannelTemp);
//            }
//            sysChannelListBean.setSysChannels1(sysChannelList1);
//
//            SysChannelOne sysChannel2 = new SysChannelOne();
//            sysChannel2.setBoardId(Long.valueOf(board));
//            sysChannel2.setFreq(Long.valueOf(queryInfo.getFreq2()));
//            List<SysChannelOne> sysChannels2 = sysChannelOneService.selectSysChannelList(sysChannel2);
//            List<SysChannel> sysChannelList2 = new ArrayList<>();
//            for (SysChannelOne channel : sysChannels2) {
//                j++;
//                String ip = channel.getIp();
//                String port = channel.getPort();
//                if (StringUtils.isEmpty(ip)){
//                    channel.setIp(tempIp+j);
//                }
//                if (StringUtils.isEmpty(port)){
//                    channel.setPort(PlayControlConfig.getChannelPort());
//                }
//                sysChannelOneService.updateSysChannel(channel);
//                SysChannel sysChannelTemp = channel.setOneObjec(channel);
//                sysChannelList2.add(sysChannelTemp);
//            }
//            sysChannelListBean.setSysChannels2(sysChannelList2);
//
//        }else if (TaskConstans.boardValue2.equals(board)){
//            SysChannelTwice sysChannel = new SysChannelTwice();
//            sysChannel.setBoardId(Long.valueOf(board));
//            sysChannel.setFreq(Long.valueOf(queryInfo.getFreq()));
//            List<SysChannelTwice> sysChannels = sysChannelTwiceService.selectSysChannelList(sysChannel);
//            String tempIp = PlayControlConfig.getChannelIpStart();
//            Integer j = 0;
//            List<SysChannel> sysChannelsList1 = new ArrayList<>();
//            for (SysChannelTwice channel : sysChannels) {
//                j++;
//                String ip = channel.getIp();
//                String port = channel.getPort();
//                if (StringUtils.isEmpty(ip)){
//                    channel.setIp(tempIp+j);
//                }
//                if (StringUtils.isEmpty(port)){
//                    channel.setPort(PlayControlConfig.getChannelPort());
//                }
//                sysChannelTwiceService.updateSysChannel(channel);
//                SysChannel sysChannelTemp = channel.setOneObjec(channel);
//                sysChannelsList1.add(sysChannelTemp);
//                System.out.println("重新赋值:"+sysChannelTemp.getPolarization()+"============"+sysChannelTemp.getSymbolRate());
//            }
//            sysChannelListBean.setSysChannels1(sysChannelsList1);
//
//            SysChannelTwice sysChannel2 = new SysChannelTwice();
//            sysChannel2.setBoardId(Long.valueOf(board));
//            sysChannel2.setFreq(Long.valueOf(queryInfo.getFreq2()));
//            List<SysChannelTwice> sysChannels2 = sysChannelTwiceService.selectSysChannelList(sysChannel2);
//            List<SysChannel> sysChannelsList2 = new ArrayList<>();
//            for (SysChannelTwice channel : sysChannels2) {
//                if (channel.getType() == 1){
//                    channel.setTypeStr("数字电视业务");
//                }else if(channel.getType() == 2){
//                    channel.setTypeStr("数字音频广播业务");
//                }
//                j++;
//                String ip = channel.getIp();
//                String port = channel.getPort();
//                if (StringUtils.isEmpty(ip)){
//                    channel.setIp(tempIp+j);
//                }
//                if (StringUtils.isEmpty(port)){
//                    channel.setPort(PlayControlConfig.getChannelPort());
//                }
//                sysChannelTwiceService.updateSysChannel(channel);
//                SysChannel sysChannelTemp = channel.setOneObjec(channel);
//                sysChannelsList2.add(sysChannelTemp);
//            }
//            sysChannelListBean.setSysChannels2(sysChannelsList2);
//        }
//        return success(sysChannelListBean);
//    }
//
//
//    @PostMapping("/getPrfDataList")
//    public AjaxResult getPrfDataList(@RequestBody QueryInfo queryInfo)
//    {
//        GetPrfDataResponse getPrfDataResponse = null;
//        String board = queryInfo.getBoard();
//        String serviceUrl = "";
//        if (TaskConstans.boardValue1.equals(board)){
//            SysBoard sysBoard = sysBoardService.selectSysBoardById(Long.valueOf(board));
//            serviceUrl = sysBoard.getUrl();
//            String freq = queryInfo.getFreq();
//            String response = sendChannelService.getPrfData(serviceUrl);
//            sysOperLogService.insertOperlogSuccess("频道管理接口.请求地址: "+serviceUrl+",响应数据:"+response);
//            if (StringUtils.isEmpty(response)){
//                sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应超时,请联系管理员检查接口服务或稍后重试");
//                return error("频道管理接口响应超时,请联系管理员检查接口服务或稍后重试");
//            }
//            ObjectMapper mapperPage = new ObjectMapper();
//            try {
//                ObjectMapper objectMapper = new ObjectMapper();
//                // 将 JSON 字符串解析为 JsonNode 对象
//                JsonNode rootNode = objectMapper.readTree(response);
//                // 获取 status 节点的值
//                int statusInt = rootNode.get("status").asInt();
//                if (statusInt == 2) {
//                    sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应状态失败，请联系管理员检查接口服务或稍后重试");
//                    logger.error("频道管理接口响应状态失败，请联系管理员检查接口服务或稍后重试");
//                } else if (statusInt == 0) {
//                    getPrfDataResponse = mapperPage.readValue(response, GetPrfDataResponse.class);
//                    List<GetPrfDataObj> data = getPrfDataResponse.getData();
//                    if (StringUtils.isNotNull(data)) {
//                        //先将已有的状态初始化
//                        List<SysChannelOne> sysChannelOnes = sysChannelOneService.selectSysChannelListByOrStatus(TaskConstans.status_selected, TaskConstans.status_selected);
//                        for (SysChannelOne sysChannelOne : sysChannelOnes) {
//                            sysChannelOne.setStatus1(TaskConstans.status_init);
//                            sysChannelOne.setStatus2(TaskConstans.status_init);
//                            sysChannelOneService.updateSysChannel(sysChannelOne);
//                        }
//                        GetPrfDataObj getPrfDataObj1 = data.get(0);
//                        GetPrfDataObj getPrfDataObj2 = data.get(1);
//                        if (StringUtils.isNotNull(getPrfDataObj1)) {
//                            List<ServiceInfo> serviceinfo = getPrfDataObj1.getServiceinfo();
//                            if (StringUtils.isNotNull(serviceinfo)){
//                                for (ServiceInfo result : serviceinfo) {
//                                    SysChannelOne sysChannel = sysChannelOneService.selectSysChannelByName(result.getName());
//                                    if (StringUtils.isNotNull(sysChannel)) {
//                                        sysChannel.setStatus1(TaskConstans.status_selected);
//                                        String url = result.getUrl();
//                                        int index1 = url.lastIndexOf("//");
//                                        int index2 = url.lastIndexOf(":");
//                                        String ip = url.substring(index1 + 2, index2);
//                                        String port = url.substring(index2+1, url.length());
//                                        sysChannel.setIp(ip);
//                                        sysChannel.setPort(port);
//                                        System.out.println("更新高频头1状态: "+sysChannel.getName()+"=========="+board+"=========="+sysChannel.getStatus1());
//                                        sysChannelOneService.updateSysChannel(sysChannel);
//                                        SysChannelOne sysChannelOne = sysChannelOneService.selectSysChannelById(sysChannel.getId());
//                                        System.out.println(sysChannelOne.getStatus1()+"============修改状态");
//
//                                        SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(result.getName());
//                                        if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                            sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                        }else{
//                                            sysChannelTemplate = new SysChannelTemplate();
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                            sysChannelTemplate.setName(result.getName());
//
//                                            List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                            sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                            sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                        }
//
//                                    }
//                                }
//                            }
//                        }
//                        if (StringUtils.isNotNull(getPrfDataObj2)) {
//                            List<ServiceInfo> serviceinfo = getPrfDataObj2.getServiceinfo();
//                            if (StringUtils.isNotNull(serviceinfo)) {
//                                for (ServiceInfo result : serviceinfo) {
//                                    SysChannelOne sysChannel = sysChannelOneService.selectSysChannelByName(result.getName());
//                                    if (StringUtils.isNotNull(sysChannel)) {
//                                        sysChannel.setStatus2(TaskConstans.status_selected);
//                                        String url = result.getUrl();
//                                        int index1 = url.lastIndexOf("//");
//                                        int index2 = url.lastIndexOf(":");
//                                        String ip = url.substring(index1 + 2, index2);
//                                        String port = url.substring(index2+1, url.length());
//                                        sysChannel.setIp(ip);
//                                        sysChannel.setPort(port);
//                                        System.out.println("更新高频头2状态: "+sysChannel.getName()+"*************"+board);
//                                        sysChannelOneService.updateSysChannel(sysChannel);
//
//                                        SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(result.getName());
//                                        if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                            sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                        }else{
//                                            sysChannelTemplate = new SysChannelTemplate();
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                            sysChannelTemplate.setName(result.getName());
//
//                                            List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                            sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                            sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
//            } catch (JsonProcessingException e) {
//                throw new RuntimeException(e);
//            }
//        }else{
//            SysBoard sysBoard = sysBoardService.selectSysBoardById(Long.valueOf(board));
//            serviceUrl = sysBoard.getUrl();
//
//            String freq = queryInfo.getFreq();
//            String response = sendChannelService.getPrfData(serviceUrl);
//            sysOperLogService.insertOperlogSuccess("频道管理接口.请求地址: "+serviceUrl+",响应数据:"+response);
//            if (StringUtils.isEmpty(response)){
//                sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应超时,请联系管理员检查接口服务或稍后重试");
//                return error("频道管理接口响应超时,请联系管理员检查接口服务或稍后重试");
//            }
//            ObjectMapper mapperPage = new ObjectMapper();
//            try {
//                ObjectMapper objectMapper = new ObjectMapper();
//                // 将 JSON 字符串解析为 JsonNode 对象
//                JsonNode rootNode = objectMapper.readTree(response);
//                // 获取 status 节点的值
//                int statusInt = rootNode.get("status").asInt();
//                if (statusInt == 2) {
//                    sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应状态失败，请联系管理员检查接口服务或稍后重试");
//                    logger.error("频道管理接口响应状态失败，请联系管理员检查接口服务或稍后重试");
//                } else if (statusInt == 0) {
//                    getPrfDataResponse = mapperPage.readValue(response, GetPrfDataResponse.class);
//                    List<GetPrfDataObj> data = getPrfDataResponse.getData();
//                    System.out.println("直播板卡2===================");
//                    if (StringUtils.isNotNull(data)) {
//                        //先将已有的状态初始化
//                        List<SysChannelTwice> sysChannelTwices = sysChannelTwiceService.selectSysChannelListByOrStatus(TaskConstans.status_selected, TaskConstans.status_selected);
//                        System.out.println("直播板卡2 已选中的频道;"+sysChannelTwices.size());
//                        for (SysChannelTwice sysChannelTwice : sysChannelTwices) {
//                            sysChannelTwice.setStatus1(TaskConstans.status_init);
//                            sysChannelTwice.setStatus2(TaskConstans.status_init);
//                            sysChannelTwiceService.updateSysChannel(sysChannelTwice);
//                            System.out.println("初始化数据");
//                        }
//                        GetPrfDataObj getPrfDataObj1 = data.get(0);
//                        GetPrfDataObj getPrfDataObj2 = data.get(1);
//                        if (StringUtils.isNotNull(getPrfDataObj1)) {
//                            List<ServiceInfo> serviceinfo = getPrfDataObj1.getServiceinfo();
//                            if (StringUtils.isNotNull(serviceinfo)){
//                                for (ServiceInfo result : serviceinfo) {
//                                    SysChannelTwice sysChannel = sysChannelTwiceService.selectSysChannelByName(result.getName());
//                                    if (StringUtils.isNotNull(sysChannel)) {
//                                        sysChannel.setStatus1(TaskConstans.status_selected);
//                                        String url = result.getUrl();
//                                        int index1 = url.lastIndexOf("//");
//                                        int index2 = url.lastIndexOf(":");
//                                        String ip = url.substring(index1 + 2, index2);
//                                        String port = url.substring(index2+1, url.length());
//                                        sysChannel.setIp(ip);
//                                        sysChannel.setPort(port);
//                                        System.out.println("更新高频头1状态: "+sysChannel.getName()+"=========="+board+"=========="+sysChannel.getStatus1());
//                                        sysChannelTwiceService.updateSysChannel(sysChannel);
//                                        SysChannelTwice sysChannel1 = sysChannelTwiceService.selectSysChannelById(sysChannel.getId());
//                                        System.out.println(sysChannel1.getStatus1()+"============修改状态");
//
//                                        SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(result.getName());
//                                        if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                            sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                        }else{
//                                            sysChannelTemplate = new SysChannelTemplate();
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                            sysChannelTemplate.setName(result.getName());
//
//                                            List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                            sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                            sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                        if (StringUtils.isNotNull(getPrfDataObj2)) {
//                            List<ServiceInfo> serviceinfo = getPrfDataObj2.getServiceinfo();
//                            if (StringUtils.isNotNull(serviceinfo)) {
//                                for (ServiceInfo result : serviceinfo) {
//                                    SysChannelTwice sysChannel = sysChannelTwiceService.selectSysChannelByName(result.getName());
//                                    if (StringUtils.isNotNull(sysChannel)) {
//                                        sysChannel.setStatus2(TaskConstans.status_selected);
//                                        String url = result.getUrl();
//                                        int index1 = url.lastIndexOf("//");
//                                        int index2 = url.lastIndexOf(":");
//                                        String ip = url.substring(index1 + 2, index2);
//                                        String port = url.substring(index2+1, url.length());
//                                        sysChannel.setIp(ip);
//                                        sysChannel.setPort(port);
//                                        System.out.println("更新高频头2状态: "+sysChannel.getName()+"*************"+board);
//                                        sysChannelTwiceService.updateSysChannel(sysChannel);
//
//
//                                        SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(result.getName());
//                                        if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                            sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                        }else{
//                                            sysChannelTemplate = new SysChannelTemplate();
//                                            sysChannelTemplate.setIp(sysChannel.getIp());
//                                            sysChannelTemplate.setPort(sysChannel.getPort());
//                                            sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                            sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                            sysChannelTemplate.setName(result.getName());
//
//                                            List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                            sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                            sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                        }
//                                    }
//                                }
//                            }
//
//                        }
//                    }
//                }
//            } catch (JsonProcessingException e) {
//                throw new RuntimeException(e);
//            }
//        }
//
//        return success(getPrfDataResponse);
//    }
//
//    @PostMapping("/refushFrequencyGpt")
//    public AjaxResult refushFrequencyGpt(@RequestBody QueryInfo queryInfo){
//        String board = queryInfo.getBoard();
//        //先重新进行一次获取所有频道的查询
////        StopChannelScanData stopChannelScanData = new StopChannelScanData();
////        stopChannelScanData.setBoard(board);
////        asyncService.sendChannelListManageDataAsync(stopChannelScanData);
//
//        String serviceUrl = "";
//        SysFreqsListBean sysFreqsListBean = new SysFreqsListBean();
//        if (TaskConstans.boardValue1.equals(board)){
//            System.out.println("直播板卡1开始查询频道数");
//            SysBoard sysBoard = sysBoardService.selectSysBoardById(Long.valueOf(board));
//            serviceUrl = sysBoard.getUrl();
//
//            String response = sendChannelService.getPrfData(serviceUrl);
//            sysOperLogService.insertOperlogSuccess("频道管理接口.请求地址: "+serviceUrl+",响应数据:"+response);
//            if (StringUtils.isEmpty(response)){
//                sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应超时,请联系管理员检查接口服务或稍后重试");
//                return error("频道管理接口响应超时,请联系管理员检查接口服务或稍后重试");
//            }
//            ObjectMapper mapperPage = new ObjectMapper();
//            GetPrfDataResponse getPrfDataResponse = null;
//            try {
//                ObjectMapper objectMapper = new ObjectMapper();
//                // 将 JSON 字符串解析为 JsonNode 对象
//                JsonNode rootNode = objectMapper.readTree(response);
//                // 获取 status 节点的值
//                int statusInt = rootNode.get("status").asInt();
//                if (statusInt == 2) {
//                    sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应状态失败，请联系管理员检查接口服务或稍后重试");
//                    logger.error("频道管理接口响应状态失败，请联系管理员检查接口服务或稍后重试");
//                } else if (statusInt == 0) {
//                    getPrfDataResponse = mapperPage.readValue(response, GetPrfDataResponse.class);
//                    List<GetPrfDataObj> data = getPrfDataResponse.getData();
//                    GetPrfDataObj getPrfDataObj1 = data.get(0);
//                    GetPrfDataObj getPrfDataObj2 = data.get(1);
//
//                    List<SysFreqOne> sysFreqListNumber = sysFreqOneService.selectSysFreqListByNumber(new SysFreqOne());
//
//                    if (StringUtils.isNotNull(getPrfDataObj1)){
//                        List<ServiceInfo> serviceinfo = getPrfDataObj1.getServiceinfo();
//                        if (StringUtils.isNotEmpty(serviceinfo)){
//                            String name = serviceinfo.get(0).getName();
//                            System.out.println("name====================="+name);
//                            SysChannelOne sysChannel = sysChannelOneService.selectSysChannelByName(name);
//                            if (StringUtils.isNotNull(sysChannel)){
//                                Long frequency1 = Long.valueOf(sysChannel.getFreq().toString());
//                                SysFreqOne sysFreq1 = sysFreqOneService.selectSysFreqByFreq(frequency1);
//                                List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                                for (SysFreqOne sysFreqOne : sysFreqListNumber) {
//                                    System.out.println("sysFreqOne "+sysFreqOne.getNumber()+"==========="+sysFreqOne.getFreq());
//                                    SysFreq sysFreq = new SysFreq();
//                                    SysFreq sysFreqNew = sysFreq.setSysFreqOne(sysFreqOne);
//                                    sysFreqsTemp.add(sysFreqNew);
//                                }
//                                sysFreqsListBean.setGpts(sysFreq1.getNumber()-1);
//                                sysFreqsListBean.setSysFreqs1(sysFreqsTemp);
//                            }
//                        }else{
//                            System.out.println("直播板卡1 serviceinfo1没有数据======================高频头1");
//                            List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                            for (SysFreqOne sysFreqOne : sysFreqListNumber) {
//                                System.out.println("serviceinfo1没有数据 sysFreqOne "+sysFreqOne.getNumber()+"==========="+sysFreqOne.getFreq());
//
//                                SysFreq sysFreq = new SysFreq();
//                                SysFreq sysFreqNew = sysFreq.setSysFreqOne(sysFreqOne);
//                                sysFreqsTemp.add(sysFreqNew);
//                            }
//                            sysFreqsListBean.setGpts(0L);
//                            sysFreqsListBean.setSysFreqs1(sysFreqsTemp);
//                        }
//                    }else{
//                        System.out.println("直播板卡1 getPrfDataObj1没有数据======================高频头1");
//                        List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                        for (SysFreqOne sysFreqOne : sysFreqListNumber) {
//                            System.out.println("getPrfDataObj1没有数据 sysFreqOne "+sysFreqOne.getNumber()+"==========="+sysFreqOne.getFreq());
//
//                            SysFreq sysFreq = new SysFreq();
//                            SysFreq sysFreqNew = sysFreq.setSysFreqOne(sysFreqOne);
//                            sysFreqsTemp.add(sysFreqNew);
//                        }
//                        sysFreqsListBean.setGpts(0L);
//                        sysFreqsListBean.setSysFreqs1(sysFreqsTemp);
//                    }
//
//                    if (StringUtils.isNotNull(getPrfDataObj2)){
//                        List<ServiceInfo> serviceinfo = getPrfDataObj2.getServiceinfo();
//                        if (StringUtils.isNotEmpty(serviceinfo)){
//
//                            String name = serviceinfo.get(0).getName();
//                            SysChannelOne sysChannel = sysChannelOneService.selectSysChannelByName(name);
//                            if (StringUtils.isNotNull(sysChannel)){
//                                Long frequency2 = Long.valueOf(sysChannel.getFreq().toString());
//                                SysFreqOne sysFreq2 = sysFreqOneService.selectSysFreqByFreq(frequency2);
//                                List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                                for (SysFreqOne sysFreqOne : sysFreqListNumber) {
//                                    System.out.println("sysFreqOne "+sysFreqOne.getNumber()+"==========="+sysFreqOne.getFreq());
//                                    SysFreq sysFreq = new SysFreq();
//                                    SysFreq sysFreqNew = sysFreq.setSysFreqOne(sysFreqOne);
//                                    sysFreqsTemp.add(sysFreqNew);
//                                }
//                                sysFreqsListBean.setGpts2(sysFreq2.getNumber()-1);
//                                sysFreqsListBean.setSysFreqs2(sysFreqsTemp);
//                            }
//                        }else{
//                            System.out.println("直播板卡1 serviceinfo2没有数据======================高频头1");
//                            List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                            for (SysFreqOne sysFreqOne : sysFreqListNumber) {
//                                System.out.println("serviceinfo2没有数据 sysFreqOne "+sysFreqOne.getNumber()+"==========="+sysFreqOne.getFreq());
//
//                                SysFreq sysFreq = new SysFreq();
//                                SysFreq sysFreqNew = sysFreq.setSysFreqOne(sysFreqOne);
//                                sysFreqsTemp.add(sysFreqNew);
//                            }
//                            sysFreqsListBean.setGpts2(0L);
//                            sysFreqsListBean.setSysFreqs2(sysFreqsTemp);
//                        }
//                    }else{
//                        System.out.println("直播板卡1 getPrfDataObj2没有数据======================高频头2");
//                        List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                        for (SysFreqOne sysFreqOne : sysFreqListNumber) {
//                            System.out.println("getPrfDataObj2没有数据 sysFreqOne "+sysFreqOne.getNumber()+"==========="+sysFreqOne.getFreq());
//
//                            SysFreq sysFreq = new SysFreq();
//                            SysFreq sysFreqNew = sysFreq.setSysFreqOne(sysFreqOne);
//                            sysFreqsTemp.add(sysFreqNew);
//                        }
//                        sysFreqsListBean.setGpts2(0L);
//                        sysFreqsListBean.setSysFreqs2(sysFreqsTemp);
//                    }
//                }
//            } catch (JsonProcessingException e) {
//                throw new RuntimeException(e);
//            }
//
//
//        }else if (TaskConstans.boardValue2.equals(board)){
//            System.out.println("直播板卡2开始查询对应频道");
//            SysBoard sysBoard = sysBoardService.selectSysBoardById(Long.valueOf(board));
//            serviceUrl = sysBoard.getUrl();
//
//            String response = sendChannelService.getPrfData(serviceUrl);
//            sysOperLogService.insertOperlogSuccess("频道管理接口.请求地址: "+serviceUrl+",响应数据:"+response);
//            if (StringUtils.isEmpty(response)){
//                sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应超时,请联系管理员检查接口服务或稍后重试");
//                return error("频道管理接口响应超时,请联系管理员检查接口服务或稍后重试");
//            }
//            ObjectMapper mapperPage = new ObjectMapper();
//            GetPrfDataResponse getPrfDataResponse = null;
//
//            try {
//                ObjectMapper objectMapper = new ObjectMapper();
//                // 将 JSON 字符串解析为 JsonNode 对象
//                JsonNode rootNode = objectMapper.readTree(response);
//                // 获取 status 节点的值
//                int statusInt = rootNode.get("status").asInt();
//                if (statusInt == 2) {
//                    sysOperLogService.insertOperlogApiError("频道管理接口.请求地址: "+serviceUrl+",响应状态失败，请联系管理员检查接口服务或稍后重试");
//                    logger.error("频道管理接口响应状态失败，请联系管理员检查接口服务或稍后重试");
//                } else if (statusInt == 0) {
//                    getPrfDataResponse = mapperPage.readValue(response, GetPrfDataResponse.class);
//                    List<GetPrfDataObj> data = getPrfDataResponse.getData();
//                    GetPrfDataObj getPrfDataObj1 = data.get(0);
//                    GetPrfDataObj getPrfDataObj2 = data.get(1);
//
//                    List<SysFreqTwice> sysFreqListNumber = sysFreqTwiceService.selectSysFreqListByNumber(new SysFreqTwice());
//
//                    if (StringUtils.isNotNull(getPrfDataObj1)){
//                        List<ServiceInfo> serviceinfo = getPrfDataObj1.getServiceinfo();
//                        if (StringUtils.isNotEmpty(serviceinfo)){
//                            String name = serviceinfo.get(0).getName();
//                            System.out.println("板卡2 name================================================="+name);
//                            SysChannelTwice sysChannel = sysChannelTwiceService.selectSysChannelByName(name);
//                            if (StringUtils.isNotNull(sysChannel)){
//                                Long frequency1 = Long.valueOf(sysChannel.getFreq().toString());
//                                SysFreqTwice sysFreq1 = sysFreqTwiceService.selectSysFreqByFreq(frequency1);
////                                List<SysFreqTwice> sysFreqsList1 = RefuseList.customSortTwice(sysFreqListNumber, sysFreq1);
//                                List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                                for (SysFreqTwice sysFreqTwice : sysFreqListNumber) {
//                                    System.out.println("sysFreqTwice "+sysFreqTwice.getNumber()+"==========="+sysFreqTwice.getFreq());
//
//                                    SysFreq sysFreq = new SysFreq();
//                                    SysFreq sysFreqNew = sysFreq.setSysFreqTwice(sysFreqTwice);
//                                    sysFreqsTemp.add(sysFreqNew);
//                                }
//                                sysFreqsListBean.setGpts(sysFreq1.getNumber()-1);
//                                sysFreqsListBean.setSysFreqs1(sysFreqsTemp);
//                            }
//                        }else{
//                            System.out.println("直播板卡2 serviceinfo1没有数据======================高频头1");
//                            List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                            for (SysFreqTwice sysFreqTwice : sysFreqListNumber) {
//                                System.out.println("serviceinfo1没有数据 sysFreqTwice "+sysFreqTwice.getNumber()+"==========="+sysFreqTwice.getFreq());
//
//                                SysFreq sysFreq = new SysFreq();
//                                SysFreq sysFreqNew = sysFreq.setSysFreqTwice(sysFreqTwice);
//                                sysFreqsTemp.add(sysFreqNew);
//                            }
//                            sysFreqsListBean.setGpts(0L);
//                            sysFreqsListBean.setSysFreqs1(sysFreqsTemp);
//                        }
//                    }else{
//                        System.out.println("直播板卡2 getPrfDataObj1没有数据======================高频头1");
//                        List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                        for (SysFreqTwice sysFreqTwice : sysFreqListNumber) {
//                            System.out.println("getPrfDataObj1没有数据 sysFreqTwice "+sysFreqTwice.getNumber()+"==========="+sysFreqTwice.getFreq());
//                            SysFreq sysFreq = new SysFreq();
//                            SysFreq sysFreqNew = sysFreq.setSysFreqTwice(sysFreqTwice);
//                            sysFreqsTemp.add(sysFreqNew);
//                        }
//                        sysFreqsListBean.setGpts(0L);
//                        sysFreqsListBean.setSysFreqs1(sysFreqsTemp);
//                    }
//
//
//                    if (StringUtils.isNotNull(getPrfDataObj2)){
//                        List<ServiceInfo> serviceinfo = getPrfDataObj2.getServiceinfo();
//                        if (StringUtils.isNotEmpty(serviceinfo)){
//
//                            String name = serviceinfo.get(0).getName();
//                            SysChannelTwice sysChannel = sysChannelTwiceService.selectSysChannelByName(name);
//                            if (StringUtils.isNotNull(sysChannel)){
//                                Long frequency2 = Long.valueOf(sysChannel.getFreq().toString());
//                                SysFreqTwice sysFreq2 = sysFreqTwiceService.selectSysFreqByFreq(frequency2);
////                                List<SysFreqTwice> sysFreqsList2 = RefuseList.customSortTwice(sysFreqListNumber, sysFreq2);
//                                List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                                for (SysFreqTwice sysFreqTwice : sysFreqListNumber) {
//                                    System.out.println("sysFreqTwice "+sysFreqTwice.getNumber()+"==========="+sysFreqTwice.getFreq());
//                                    SysFreq sysFreq = new SysFreq();
//                                    SysFreq sysFreqNew = sysFreq.setSysFreqTwice(sysFreqTwice);
//                                    sysFreqsTemp.add(sysFreqNew);
//                                }
//                                sysFreqsListBean.setGpts2(sysFreq2.getNumber()-1);
//                                sysFreqsListBean.setSysFreqs2(sysFreqsTemp);
//                            }
//                        }else{
//                            System.out.println("直播板卡2 serviceinfo2没有数据======================高频头1");
//                            List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                            for (SysFreqTwice sysFreqTwice : sysFreqListNumber) {
//                                System.out.println("serviceinfo2没有数据 sysFreqTwice "+sysFreqTwice.getNumber()+"==========="+sysFreqTwice.getFreq());
//                                SysFreq sysFreq = new SysFreq();
//                                SysFreq sysFreqNew = sysFreq.setSysFreqTwice(sysFreqTwice);
//                                sysFreqsTemp.add(sysFreqNew);
//                            }
//                            sysFreqsListBean.setGpts2(0L);
//                            sysFreqsListBean.setSysFreqs2(sysFreqsTemp);
//                        }
//                    }else{
//                        System.out.println("直播板卡2 getPrfDataObj2没有数据======================高频头2");
//                        List<SysFreq> sysFreqsTemp = new ArrayList<>();
//                        for (SysFreqTwice sysFreqTwice : sysFreqListNumber) {
//                            System.out.println("getPrfDataObj2没有数据 sysFreqTwice "+sysFreqTwice.getNumber()+"==========="+sysFreqTwice.getFreq());
//                            SysFreq sysFreq = new SysFreq();
//                            SysFreq sysFreqNew = sysFreq.setSysFreqTwice(sysFreqTwice);
//                            sysFreqsTemp.add(sysFreqNew);
//                        }
//                        sysFreqsListBean.setGpts2(0L);
//                        sysFreqsListBean.setSysFreqs2(sysFreqsTemp);
//                    }
//                }
//            } catch (JsonProcessingException e) {
//                throw new RuntimeException(e);
//            }
//        }
//
//        return success(sysFreqsListBean);
//    }
//
//    @PostMapping("/setMainFreqEx")
//    public AjaxResult setMainFreqEx(@Validated @RequestBody DeliveryParamObject deliveryParamObject){
//
//        String bordId = deliveryParamObject.getBordId();
//        List<DeliveryParam> deliveryParam = deliveryParamObject.getDeliveryParam();
//        System.out.println("===deliveryParam size======"+deliveryParam.size());
//        Integer deliveryType = 10;
//        MainFreqParameters mainFreqParameters = new MainFreqParameters();
//        List<FreqInfo> freqs = new ArrayList<>();
//        FreqInfo freqInfo = new FreqInfo();
//        freqInfo.setDeliveryType(deliveryType);
//        freqInfo.setDeliveryParams(deliveryParam);
//        System.out.println("===setDeliveryParams size===="+freqInfo.getDeliveryParams().size());
//        freqs.add(freqInfo);
//        mainFreqParameters.setFreqInfo(freqs);
//        SysBoard sysBoard = sysBoardService.selectSysBoardById(Long.valueOf(bordId));
//        String serviceUrl = sysBoard.getUrl();
//        String response = sendChannelService.setMainFreqEx(serviceUrl, mainFreqParameters);
//        try {
//            ObjectMapper objectMapper = new ObjectMapper();
//            // 将 JSON 字符串解析为 JsonNode 对象
//            JsonNode rootNode = objectMapper.readTree(response);
//            // 获取 status 节点的值
//            int statusInt = rootNode.get("status").asInt();
//            if (statusInt == 0){
//                return success(true);
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//            return success(false);
//        }
//
//        return success(false);
//    }
//    @PostMapping("/setPrfDataSave")
//    public AjaxResult setPrfDataSave(@Validated @RequestBody SaveSatelliteInfo saveSatelliteInfo){
//        System.out.println("setPrfDataSave: "+saveSatelliteInfo.toString());
//        String satellite = saveSatelliteInfo.getSatellite(); //1表示高频头1  2表示高频头2
//        String board = saveSatelliteInfo.getBoard();
//        String serviceUrl = "";
//
//        if (TaskConstans.boardValue1.equals(board)){
//            SysBoard sysBoard = sysBoardService.selectSysBoardById(Long.valueOf(board));
//            serviceUrl = sysBoard.getUrl();
//
//            List<SaveServiceInfo> serviceInfo = saveSatelliteInfo.getServiceInfo();
//
//            //校验频道是否有重复选择
//            System.out.println("校验选择保存频道是否有重复");
//            Set<String> names = new HashSet<>();
//            Set<String> ips = new HashSet<>();
//            Set<String> selectIps = new HashSet<>(); //校验选中的频道分配的ip是否有重复
//            List<SysChannelTwice> sysChannelsStore = sysChannelTwiceService.selectSysChannelListByOrStatus(TaskConstans.status_selected,TaskConstans.status_selected);
//            for (SysChannelTwice channel : sysChannelsStore) {
//                System.out.println("另一个直播板卡的频道,即从数据库中查询到的直播板卡2的频道名称:"+channel.getName());
//                names.add(channel.getName());
//                ips.add(channel.getIp());
//
//            }
//            System.out.println("获取另一个直播板卡保存的直播频道数:"+names.size());
//            List<String> selectNames1 = new ArrayList<>();
//            List<String> selectNames2 = new ArrayList<>();
//            SaveServiceInfo saveServiceInfo1 = serviceInfo.get(0);
//            if (StringUtils.isNotNull(saveServiceInfo1)){
//                List<SaveService> serviceinfo = saveServiceInfo1.getServiceinfo();
//                for (SaveService saveService : serviceinfo) {
//                    String name = saveService.getName();
//                    String ip = saveService.getIp();
//                    selectNames1.add(name);
//                    if(!selectIps.add(ip)){
//                        System.out.println("===================保存频道有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" ,分配的输出地址: "+ip+" 有重复,建议重新修改该输出地址");
//                        return success(checkChannelBean);
//                    }
//                    if (!names.add(name)){
//                        System.out.println("===================保存频道有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" 在直播板卡2的高频头1已分发,请重新选择");
//                        return success(checkChannelBean);
//                    }else if(!ips.add(ip)){
//                        System.out.println("===================保存频道IP有重复====================:"+ip);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" 的输出地址: "+ip+" ,在直播板卡2的高频头1已分发,建议手动修改该输出地址");
//                        return success(checkChannelBean);
//                    }else{
//                        System.out.println("=========================保存频道没有重复=============`"+name);
//                    }
//                }
//            }
//            SaveServiceInfo saveServiceInfo2 = serviceInfo.get(1);
//            if (StringUtils.isNotNull(saveServiceInfo2)){
//                List<SaveService> serviceinfo = saveServiceInfo2.getServiceinfo();
//                for (SaveService saveService : serviceinfo) {
//                    String name = saveService.getName();
//                    String ip = saveService.getIp();
//                    selectNames2.add(name);
//                    if(!selectIps.add(ip)){
//                        System.out.println("===================保存频道有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" ,分配的输出地址: "+ip+" 有重复,建议重新修改该输出地址");
//                        return success(checkChannelBean);
//                    }
//                    if (!names.add(name)){
//                        System.out.println("===================保存频道有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" 在直播板卡2的高频头2已分发,请重新选择");
//                        return success(checkChannelBean);
//                    }else if(!ips.add(ip)){
//                        System.out.println("===================保存频道IP有重复====================:"+ip);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" 的输出地址: "+ip+" ,在直播板卡2的高频头2已分发,建议手动修改该输出地址");
//                        return success(checkChannelBean);
//                    }else{
//                        System.out.println("=========================保存频道没有重复=============`"+name);
//                    }
//                }
//            }
//
//            String response = sendChannelService.setPrfData(serviceInfo,serviceUrl,board);
//            sysOperLogService.insertOperlogSuccess("频道输出接口.请求地址: "+serviceUrl+",响应数据:"+response);
//            if (StringUtils.isEmpty(response)){
//                sysOperLogService.insertOperlogApiError("频道输出设置接口.请求地址: "+serviceUrl+",响应超时,请联系管理员检查接口服务或稍后重试");
//                return error("频道输出设置接口响应超时,请联系管理员检查接口服务或稍后重试");
//            }
//            ObjectMapper mapperPage = new ObjectMapper();
//            GetPrfDataResponse getPrfDataResponse = null;
//            try {
//                ObjectMapper objectMapper = new ObjectMapper();
//                // 将 JSON 字符串解析为 JsonNode 对象
//                JsonNode rootNode = objectMapper.readTree(response);
//                // 获取 status 节点的值
//                int statusInt = rootNode.get("status").asInt();
//                if (statusInt != 0) {
//                    sysOperLogService.insertOperlogApiError("频道输出设置接口.请求地址: "+serviceUrl+",响应状态失败，请联系管理员检查接口服务或稍后重试");
//                    return error("频道输出设置接口响应状态失败，请联系管理员检查接口服务或稍后重试");
//                }else{
//                    //先一律将上一次选中的频道状态恢复为初始状态,再将这次选中的状态更新
//                    List<SysChannelOne> sysChannelOnes = sysChannelOneService.selectSysChannelListByOrStatus(TaskConstans.status_selected, TaskConstans.status_selected);
//                    for (SysChannelOne sysChannelOne : sysChannelOnes) {
//                        sysChannelOne.setStatus1(TaskConstans.status_init);
//                        sysChannelOne.setStatus2(TaskConstans.status_init);
//                        sysChannelOneService.updateSysChannel(sysChannelOne);
//
//                        SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(sysChannelOne.getName());
//                        if(StringUtils.isNotNull(sysChannelTemplate)){
//                            sysChannelTemplate.setStatus(TaskConstans.status_init);
//                            sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                        }
//                    }
//                    if (StringUtils.isNotNull(getPrfDataResponse)){
//                        List<GetPrfDataObj> data = getPrfDataResponse.getData();
//                        if (StringUtils.isNotNull(data)){
//                            GetPrfDataObj dataObj1 = data.get(0);
//                            GetPrfDataObj dataObj2 = data.get(1);
//                            List<ServiceInfo> serviceinfo1 = dataObj1.getServiceinfo();
//                            for (ServiceInfo info : serviceinfo1) {
//                                String name = info.getName();
//                                SysChannelOne temp = new SysChannelOne();
//                                temp.setName(name);
//                                temp.setStatus1(TaskConstans.status_selected);
//                                sysChannelOneService.updateSysChannel(temp);
//
//                                SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(temp.getName());
//                                if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                    sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                }else{
//                                    sysChannelTemplate = new SysChannelTemplate();
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                    sysChannelTemplate.setName(temp.getName());
//
//                                    List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                    sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                    sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                }
//                            }
//                            List<ServiceInfo> serviceinfo = dataObj2.getServiceinfo();
//                            for (ServiceInfo info : serviceinfo) {
//                                String name = info.getName();
//                                SysChannelOne temp = new SysChannelOne();
//                                temp.setName(name);
//                                temp.setStatus2(TaskConstans.status_selected);
//                                sysChannelOneService.updateSysChannel(temp);
//
//                                SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(temp.getName());
//                                if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                    sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                }else{
//                                    sysChannelTemplate = new SysChannelTemplate();
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                    sysChannelTemplate.setName(temp.getName());
//
//                                    List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                    sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                    sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                }
//                            }
//                        }
//                    }
//                    CheckChannelBean checkChannelBean = new CheckChannelBean();
//                    checkChannelBean.setFlag(true);
//                    return success(checkChannelBean);
//                }
//            } catch (JsonProcessingException e) {
//                throw new RuntimeException(e);
//            }
//
//
//        }else if (TaskConstans.boardValue2.equals(board)){
//            SysBoard sysBoard = sysBoardService.selectSysBoardById(Long.valueOf(board));
//            serviceUrl = sysBoard.getUrl();
//            List<SaveServiceInfo> serviceInfo = saveSatelliteInfo.getServiceInfo();
//
//            //校验频道是否有重复选择
//            System.out.println("校验选择保存频道是否有重复");
//            Set<String> names = new HashSet<>();
//            Set<String> ips = new HashSet<>();
//            List<SysChannelOne> sysChannelsStore = sysChannelOneService.selectSysChannelListByOrStatus(TaskConstans.status_selected,TaskConstans.status_selected);
//            for (SysChannelOne channel : sysChannelsStore) {
//                System.out.println("另一个直播板卡的频道,即从数据库中查询到的直播板卡1的频道名称:"+channel.getName());
//                names.add(channel.getName());
//                ips.add(channel.getIp());
//            }
//            System.out.println("获取另一个直播板卡保存的直播频道数:"+names.size());
//            List<String> selectNames1 = new ArrayList<>();
//            List<String> selectNames2 = new ArrayList<>();
//            List<String> selectIps = new ArrayList<>();
//            SaveServiceInfo saveServiceInfo1 = serviceInfo.get(0);
//            if (StringUtils.isNotNull(saveServiceInfo1)){
//                List<SaveService> serviceinfo = saveServiceInfo1.getServiceinfo();
//                for (SaveService saveService : serviceinfo) {
//                    String name = saveService.getName();
//                    String ip = saveService.getIp();
//                    selectNames1.add(name);
//                    if(!selectIps.add(ip)){
//                        System.out.println("===================保存频道有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" ,分配的输出地址: "+ip+" 有重复,建议重新修改该输出地址");
//                        return success(checkChannelBean);
//                    }
//                    if (!names.add(name)){
//                        System.out.println("===================保存频道名称有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" 在直播板卡1的高频头1已分发,请重新选择");
//                        return success(checkChannelBean);
//                    }if(!ips.add(ip)){
//                        System.out.println("===================保存频道IP有重复====================:"+ip);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" 的输出地址: "+ip+" ,在直播板卡1的高频头1已分发,建议手动修改该输出地址");
//                        return success(checkChannelBean);
//                    }else{
//                        System.out.println("=========================保存频道没有重复=============`"+name);
//                    }
//                }
//            }
//
//            SaveServiceInfo saveServiceInfo2 = serviceInfo.get(1);
//            if (StringUtils.isNotNull(saveServiceInfo2)){
//                List<SaveService> serviceinfo = saveServiceInfo2.getServiceinfo();
//                for (SaveService saveService : serviceinfo) {
//                    String name = saveService.getName();
//                    String ip = saveService.getIp();
//                    selectNames2.add(name);
//                    if(!selectIps.add(ip)){
//                        System.out.println("===================保存频道有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" ,分配的输出地址: "+ip+" 有重复,建议重新修改该输出地址");
//                        return success(checkChannelBean);
//                    }
//                    if (!names.add(name)){
//                        System.out.println("===================保存频道有重复====================:"+name);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道在直播板卡1的高频头2已分发,请重新选择");
//                        return success(checkChannelBean);
//                    }else if(!ips.add(ip)){
//                        System.out.println("===================保存频道IP有重复====================:"+ip);
//                        CheckChannelBean checkChannelBean = new CheckChannelBean();
//                        checkChannelBean.setFlag(false);
//                        checkChannelBean.setMessage("保存失败:当前选择的频道: "+name+" 的输出地址: "+ip+" ,在直播板卡1的高频头2已分发,建议手动修改该输出地址");
//                        return success(checkChannelBean);
//                    }else{
//                        System.out.println("=========================保存频道没有重复=============`"+name);
//                    }
//                }
//            }
//
//            String response = sendChannelService.setPrfData(serviceInfo,serviceUrl,board);
//            sysOperLogService.insertOperlogSuccess("频道输出接口.请求地址: "+serviceUrl+",响应数据:"+response);
//            if (StringUtils.isEmpty(response)){
//                sysOperLogService.insertOperlogApiError("频道输出设置接口.请求地址: "+serviceUrl+",响应超时,请联系管理员检查接口服务或稍后重试");
//                return error("频道输出设置接口响应超时,请联系管理员检查接口服务或稍后重试");
//            }
//            ObjectMapper mapperPage = new ObjectMapper();
//            GetPrfDataResponse getPrfDataResponse = null;
//            try {
//                ObjectMapper objectMapper = new ObjectMapper();
//                // 将 JSON 字符串解析为 JsonNode 对象
//                JsonNode rootNode = objectMapper.readTree(response);
//                // 获取 status 节点的值
//                int statusInt = rootNode.get("status").asInt();
//                if (statusInt != 0) {
//                    sysOperLogService.insertOperlogApiError("频道输出设置接口.请求地址: "+serviceUrl+",响应状态失败，请联系管理员检查接口服务或稍后重试");
//                    return error("频道输出设置接口响应状态失败，请联系管理员检查接口服务或稍后重试");
//                }else{
//                    //先一律将上一次选中的频道状态恢复为初始状态,再将这次选中的状态更新
//                    List<SysChannelTwice> sysChannelTwices = sysChannelTwiceService.selectSysChannelListByOrStatus(TaskConstans.status_selected, TaskConstans.status_selected);
//                    for (SysChannelTwice sysChannelTwice : sysChannelTwices) {
//                        sysChannelTwice.setStatus1(TaskConstans.status_init);
//                        sysChannelTwice.setStatus2(TaskConstans.status_init);
//                        sysChannelTwiceService.updateSysChannel(sysChannelTwice);
//
//                        SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(sysChannelTwice.getName());
//                        if(StringUtils.isNotNull(sysChannelTemplate)){
//                            sysChannelTemplate.setStatus(TaskConstans.status_init);
//                            sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                        }
//                    }
//                    if (StringUtils.isNotNull(getPrfDataResponse)){
//                        List<GetPrfDataObj> data = getPrfDataResponse.getData();
//                        if (StringUtils.isNotNull(data)){
//                            GetPrfDataObj dataObj1 = data.get(0);
//                            GetPrfDataObj dataObj2 = data.get(1);
//                            List<ServiceInfo> serviceinfo1 = dataObj1.getServiceinfo();
//                            for (ServiceInfo info : serviceinfo1) {
//                                String name = info.getName();
//                                SysChannelTwice temp = new SysChannelTwice();
//                                temp.setName(name);
//                                temp.setStatus1(TaskConstans.status_selected);
//                                sysChannelTwiceService.updateSysChannel(temp);
//
//                                SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(temp.getName());
//                                if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                    sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                }else{
//                                    sysChannelTemplate = new SysChannelTemplate();
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                    sysChannelTemplate.setName(temp.getName());
//
//                                    List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                    sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                    sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                }
//                            }
//                            List<ServiceInfo> serviceinfo = dataObj2.getServiceinfo();
//                            for (ServiceInfo info : serviceinfo) {
//                                String name = info.getName();
//                                SysChannelTwice temp = new SysChannelTwice();
//                                temp.setName(name);
//                                temp.setStatus2(TaskConstans.status_selected);
//                                sysChannelTwiceService.updateSysChannel(temp);
//
//                                SysChannelTemplate sysChannelTemplate = sysChannelTemplateService.selectSysChannelTemplateByName(temp.getName());
//                                if (StringUtils.isNotNull(sysChannelTemplate)) {
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//
//                                    sysChannelTemplateService.updateSysChannelTemplate(sysChannelTemplate);
//                                }else{
//                                    sysChannelTemplate = new SysChannelTemplate();
//                                    sysChannelTemplate.setIp(temp.getIp());
//                                    sysChannelTemplate.setPort(temp.getPort());
//                                    sysChannelTemplate.setStatus(TaskConstans.status_selected);
//                                    sysChannelTemplate.setBoardId(Long.valueOf(board));
//                                    sysChannelTemplate.setName(temp.getName());
//
//                                    List<SysChannelTemplate> sysChannelTemplates = sysChannelTemplateService.selectSysChannelTemplateListByChannelId(new SysChannelTemplate());
//                                    sysChannelTemplate.setChannelId(sysChannelTemplates.get(sysChannelTemplates.size()).getChannelId()+1);
//                                    sysChannelTemplateService.insertSysChannelTemplate(sysChannelTemplate);
//                                }
//                            }
//                        }
//                    }
//                    CheckChannelBean checkChannelBean = new CheckChannelBean();
//                    checkChannelBean.setFlag(true);
//                    return success(checkChannelBean);
//                }
//            } catch (JsonProcessingException e) {
//                throw new RuntimeException(e);
//            }
//        }
//        CheckChannelBean checkChannelBean = new CheckChannelBean();
//        checkChannelBean.setFlag(false);
//        return success(checkChannelBean);
//
//
//    }
//}
